from langchain_core.output_parsers import StrOutputParser

from langchain_core.prompts import ChatPromptTemplate
from langchain.chat_models import ChatOpenAI

from dotenv import load_dotenv,find_dotenv
_=load_dotenv(find_dotenv())

"""测试·1
prompt = ChatPromptTemplate.from_template("帮我讲一个笑话，关于 {topic} ")
model = ChatOpenAI(temperature=0.7,model = 'gpt-4')
output_parser = StrOutputParser()

chain = prompt | model | output_parser
# invoke 需要一个json，字典对象，进行传递
# 这里会自动将topic这个变量赋值
print(chain.invoke({"topic": "小狗下蛋"}))
"""
"""测试2"""
prompt = ChatPromptTemplate.from_template("帮我讲一个笑话，关于 {topic} ")
# prompt 是 PromptValue 类型
print(prompt.invoke({"topic": "小狗下蛋"})
)
